local function fx()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddNetwork()


    inst:AddTag("INLIMBO")
    inst:AddTag("FX")
    inst:AddTag("npc_fx_tophat_first_gift_fx")

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("npc_base_lib")
    inst:AddComponent("npc_everything_data")

    inst:DoTaskInTime(0.5,function()
        local pt = Vector3( inst.Transform:GetWorldPosition() )
        local fx = SpawnPrefab("npc_fx_star_door")
        fx:PushEvent("Set",{
            pt = pt,
            scale = Vector3(2,2,2),
            appear = true,

            appear_anim_speed_mult = 30,
            idle_anim_speed_mult = 5,
            disappear_anim_speed_mult = 30,

            layer = LAYER_WORLD_BACKGROUND,
            orientation = ANIM_ORIENTATION.OnGround,
            sort = 0,
        })
        inst.fx = fx
    end)
    inst:DoPeriodicTask(1,function()
        local x,y,z = inst.Transform:GetWorldPosition()
        local ents = TheSim:FindEntities(x, y, z, 2.5, {"npc_item_magic_tophat"}, nil, nil)
        if #ents == 0 then
            if inst.fx then
                inst.fx:PushEvent("Set",{
                    disappear_anim_speed_mult = 30,
                    disappear = true
                })
            end
            inst:Remove()
        else
            local hat = ents[1]
            if hat and hat.prefab == "npc_item_magic_tophat" and inst.npc_everything_data:Add("time",1) > 10 and inst:IsNearPlayer(30) == false then
                inst.npc_everything_data:Set("time",0)
                inst.npc_base_lib:Change_Item_Skin(hat) 
            end
        end
    end)
    
    return inst
end

return Prefab("npc_fx_tophat_first_gift_fx",fx)